package com.yuejian.neusoft.yuejian_24.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian.neusoft.yuejian_24.R;
import com.yuejian.neusoft.yuejian_24.activity.MarchDetailActivity;
import com.yuejian.neusoft.yuejian_24.javaBean.March;

import java.util.List;

/**
 * Created by q4549 on 2017/10/13.
 */

public class MarchListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public MarchListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.march_cardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final March entity = (March) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.game_name.setText(entity.getMarch_name());
        Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/photo/"+entity.getMarch_pic()).into(viewHolder.game_img);
        viewHolder.game_container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, MarchDetailActivity.class);
                intent.putExtra("url",entity.getMarch_web());
                intent.putExtra("march_id",entity.getMarch_id());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView game_img;
        TextView game_name;
        FrameLayout game_container;

        public ViewHolder(View itemView) {
            super(itemView);
            game_name = (TextView) itemView.findViewById(R.id.game_name);
            game_img = (ImageView) itemView.findViewById(R.id.game_img);
            game_container= (FrameLayout)itemView.findViewById(R.id.game_container);
        }
    }

}
